package annotation.load;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

//测试类的初始化，发生时间
public class ClassConstruct {
    static {
        System.out.println("Main类加载");
    }

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //1.主动引用
        //Son son = new Son();
        //反射也会发生主动引用
        Class sonClass = Class.forName("annotation.load.Son");
        Constructor constructor = sonClass.getDeclaredConstructor();
        Son son = (Son) constructor.newInstance();
        System.out.println(son.name);
    }
}

class Father {

    static int b = 2;

    static {
        System.out.println("父类加载");
    }
}

class Son extends Father {
    static {
        System.out.println("子类加载");
        name = "Cph";
    }

    static String name = "Lby";
    static final int M = 1;

}